home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5245 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  123 lines

  1. Path: newsfeed.direct.ca!usenet
  2. From: etoivane@direct.ca (Ed Toivanen)
  3. Newsgroups: comp.lang.c
  4. Subject: gets(rec->num);  I don't know what I am doing wrong...
  5. Date: 9 Feb 1996 05:41:17 GMT
  6. Organization: Your Organization
  7. Message-ID: <4fempt$mjg@aphex.direct.ca>
  8. NNTP-Posting-Host: 204.174.244.95
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.6
  12.  
  13. I posted the code that I wrote so far.  I can't make gets(rec->id); work 
  14. properly,  I get 6 or 7 compilation errors indicating that parameter 1 does not 
  15. match function prototype.  Each gets() call is incorrect! What to do? 
  16. /*
  17.         Ed Toivanen
  18.         Assign2
  19.         Comp 3425(Wed)
  20.         Feb 5, 1996
  21. */
  22. #define NAME_LEN 40
  23.  
  24. typedef enum {FALSE, TRUE} bool;
  25.  
  26. typedef enum {SCIENCE, ART} PROGRAM;
  27.  
  28. typedef struct science_mark {
  29.     int math, physics, compsci; /* Range: 0..100 */
  30. }SCIENCE_MARK;
  31.  
  32. typedef struct art_mark {
  33.     int acting, dancing;        /* Range: 0..100 */
  34. }ART_MARK;
  35.  
  36. typedef union mark {
  37.     SCIENCE_MARK scientist;
  38.     ART_MARK artist;
  39. }MARK;
  40.  
  41. typedef struct student_record{
  42.     int id;                     /* Range: 1..99, Unique */
  43.     char name[NAME_LEN + 1];    /* Non-unique */
  44.     PROGRAM major;
  45.     MARK marks;
  46. } STUDENT_RECORD;
  47.     
  48.  
  49. /*
  50.         Assign2.c
  51. */
  52.  
  53. #include<stdio.h>
  54. #include"assign2.h"
  55.  
  56. bool initList(char*, FILE*);
  57. bool addRecord(FILE*, STUDENT_RECORD*);
  58. bool deleteRecord(FILE*, STUDENT_RECORD*);
  59. bool searchforRecord(FILE*, STUDENT_RECORD*);
  60. bool printList(FILE*);
  61. bool printRecord(FILE*, STUDENT_RECORD*);
  62.  
  63. int main(void){
  64.     char studentList[8 + 1];
  65.     FILE * filePtr;
  66.  
  67.     printf("Enter database file to open\n");
  68.     while(!gets(studentList))
  69.         {}
  70.     
  71.     if(!initList(studentList, filePtr)){
  72.         return(1);
  73.     }
  74.  
  75.     return(0);
  76. }    
  77.  
  78. bool initList(char* list, FILE* fp){
  79.     if(!(fp = fopen(list, "wb"))){
  80.         printf("Error opening %s\n", list);
  81.         fclose(fp);
  82.         return(FALSE);
  83.     }
  84.     else
  85.         return(TRUE);
  86. }           
  87.  
  88. bool addRecord(FILE* fp, STUDENT_RECORD* rec){
  89.     printf("Student id\n");
  90.     gets(rec->id);
  91.     
  92.     printf("Student's last name first\n");
  93.     gets(rec->name);       
  94.  
  95.     printf("Major\n");
  96.     gets(rec->major);
  97.  
  98.     printf("Grades\n");
  99.     switch(rec->major){
  100.         case SCIENCE:
  101.                printf("Math\n");
  102.                fprintf(fp, gets(rec->marks.scientist.math));
  103.                
  104.                printf("Physics\n");
  105.                fprintf(fp, gets(rec->marks.scientist.physics));
  106.                
  107.                printf("Compsci\n");
  108.                fprintf(fp, gets(rec->marks.scientist.compsci));
  109.                break;
  110.         case ART:
  111.                printf("Acting\n");
  112.                fprintf(fp, gets(rec->marks.artist.acting));
  113.                
  114.                printf("Dancing\n");
  115.                fprintf(fp, gets(rec->marks.artist.dancing));
  116.                break;
  117.         default :
  118.                break;
  119.     }
  120.     return(TRUE);
  121. }/*End addRec*/                      
  122.  
  123.